
(* 
   Write a function triple : string -> string that takes a string
   argument and returns a new string that repeats the given string three
   times. For instance: triple("Ohmy") ---> "OhmyOhmyOhmy"
*) 

(* 

(a) Does the following declaration typecheck? If so, what is the name
of the identifier being declared and what are the type and value to
which it is bound?  fun f(x) = 1 + f(x+1)

(b) Given the function f as above, does the following expression
typecheck? If so, what are its type and value?  f(0)

Write an SML function digcount : int * int -> int such that digcount(d, n) evaluates to
the number of times the digit d appears in the decimal representation of the natural number n
(ignoring leading zeros). Note that 0 <= d <= 9 and n >= 0. Here are some examples:
digcount(0, 0) ---> 1
digcount(7, 0) ---> 0
digcount(0, 1023004) ---> 3
digcount(3, 1023004) ---> 1
digcount(0, 04050) ---> 2
digcount(4, 474516) ---> 2


One method for computing cube roots is based on an iterative formula called Newton’s method.
The cube root r^1/3 of a non-zero real number r is iteratively approximated by the following rules:

x_0 = r
x_n+1 = 2 x_n^3 + r
n + r
3 x2
n
, for n = 0, 1, 2, . . .
In other words, the new estimate xn+1 is the weighted average of the old estimate xn and r/x2
n.
In order to compute the cube root of r, one iteratively applies the last rule until the
approximation is “good enough”. One test of “good enough” is to check that the residual |x3
n
−r|
is less than some prespecified positive threshold eps. Convergence of Newton’s method is generally
very fast.
Write an SML function cuberoot : real * real -> real. The function should take a pair
(r, eps) as argument, with eps > 0. It should iteratively compute the cube root of r using the
threshold eps as described above. For instance,
cuberoot(~19.0, 0.0005) → ~2.668402 (approximately).
Your function should work for positive and negative values of r, as well as for r = 0.0.

*) 



(* 
   Write a function twicemore : int * float -> bool. The function
   should take a pair consisting of an integer and a real number as
   argument and return a boolean. The function should return true if
   the integer is strictly greater than twice the real number, and
   false otherwise. For instance:

   twicemore(4, 3.1) ---> false
   twicemore(3, 1.4) ---> true
*) 

let twicemore : int * real -> bool =
  fun _ -> raise Unimplemented 
